<div class="judul"><?php echo anchor("/rekap_keuangan_bulanan/", $title);?></div>
<script type="text/javascript">
  $(document).ready(function(){
      $('.check').removeAttr('checked');
      $('.jumlah').attr('disabled', 'disabled');
      $('.checkAll').val('1');
      
      $('#checkAll').click(function(){
          if($('.checkAll').val() == 1){
              $('.check').attr('checked', 'checked');
              $('.jumlah').removeAttr('disabled');
              $('.checkAll').val('0');
          }else{
              $('.check').removeAttr('checked');
              $('.jumlah').attr('disabled','disabled');
              $('.checkAll').val('1');
          }
      })
  })  
  function checkList(obj){
      if($(obj).next().is(':disabled')){
          $(obj).next().removeAttr('disabled');
      }else{
          $(obj).next().attr('disabled','disabled');
      }
  }
</script>
<?php
$bulan = $this->uri->segment(3)!=""?$this->uri->segment(3):"";
$thn = $this->uri->segment(4)!=""?$this->uri->segment(4):"";
$flashdata = $this->session->flashdata('message');
$messages = isset ($flashdata)?pesan($flashdata):"";
echo "$messages";
$disable = "disabled='disabled'";
?>
<?php
  echo form_open($subLink);
?>
<div class="data-input">
    <fieldset>
        <legend><?php echo "$formTitle";?></legend>
        <table width="100%">
            <tr>
                <td valign="top" width="50%">
                    <fieldset class="field-group">
                        <label>Bulan & Tahun</label>
                        <select name="bulan" id="bulan" style="min-width: 10em;">
                            <option value="01" <?php if($bulan == 01) echo "selected='selected'";?>>Januari</option>
                            <option value="02" <?php if($bulan == 02) echo "selected='selected'";?>>Februari</option>
                            <option value="03" <?php if($bulan == 03) echo "selected='selected'";?>>Maret</option>
                            <option value="04" <?php if($bulan == 04) echo "selected='selected'";?>>April</option>
                            <option value="05" <?php if($bulan == 05) echo "selected='selected'";?>>Mei</option>
                            <option value="06" <?php if($bulan == 06) echo "selected='selected'";?>>Juni</option>
                            <option value="07" <?php if($bulan == 07) echo "selected='selected'";?>>Juli</option>
                            <option value="08" <?php if($bulan == 08) echo "selected='selected'";?>>Agustus</option>
                            <option value="09" <?php if($bulan == 09) echo "selected='selected'";?>>September</option>
                            <option value="10" <?php if($bulan == 10) echo "selected='selected'";?>>Oktober</option>
                            <option value="11" <?php if($bulan == 11) echo "selected='selected'";?>>November</option>
                            <option value="12" <?php if($bulan == 12) echo "selected='selected'";?>>Desember</option>
                        </select>
                        <select name="tahun" id="tahun" style="min-width: 10em;">
                            <?php
                              $tahun = date("Y");
                              for($tahun;$tahun >= 2008;$tahun--){
                            ?>
                            <option value="<?php echo "$tahun";?>" <?php if($tahun == $thn) echo "selected='selected'";?>><?php echo "$tahun";?></option>
                            <?php
                              }
                            ?>
                        </select>
                        <fieldset class="input-process">
                           <?php 
                                echo form_hidden("url", $searchLink);
                                echo form_submit("tampil","Tampil", "class='button' style='margin-right:2px'");
                                echo form_button('Batal','Batal', 'class=button onClick='."javascript:location.href='".base_url()."index.php/rekap_keuangan_bulanan/'".'');
                           ?>
                        </fieldset>
                    </fieldset>
                </td>
                <td valign="top">
                    <fieldset>
                        <legend>Keterangan</legend>
                        <span style="width:5em;background: #fed6db">&nbsp;</span>&nbsp;: Unapproved<br /><br />
                        <span style="width:5em;background: #d6fedb">&nbsp;</span>&nbsp;: Approved
                    </fieldset>
                </td>
            </tr>
        </table>
    </fieldset>
</div>
<?php
  echo form_close();
  echo form_open('rekap_keuangan_bulanan/rekap_keuangan_bulanan_proses');
?>
<fieldset style="border: 1px dotted #999999">
<legend>Keuangan Donatur Tunggal</legend>    
<div class="data-list">
    <table class="tabel" style="width:100%">
        <tr>
            <th>Donatur Tunggal</th>
            <th>Tanggal</th>
            <th>Petugas</th>
            <th>Keterangan</th>
            <th>Debet(Rp.)</th>
            <th>Kredit(Rp.)</th>
            <th>Saldo(Rp.)</th>
            <th>Aksi</th>
        </tr>
        <?php
          $debet = 0;
          $kredit = 0;
          foreach ($listKeuanganDonaturTunggal as $key => $row){
        ?>
          <tr>
            <td rowspan="<?php echo count($row['detail'])?>" style="vertical-align: middle;min-width: 15%"><?php echo $row['donaturTunggal']['nama']?></td>
        <?php
              foreach ($row['detail'] as $rowz){
              ($rowz['status'] == 0)?$style = "background:#fed6db;": $style = "background:#d6fedb;";
              if($rowz['status'] == 0) $disable = "";
        ?>
            <td style="<?php echo "$style";?>"><?php echo datefmysql($rowz['tanggal']);?></td>
            <td style="<?php echo "$style";?>"><?php echo $rowz['petugas'];?></td>
            <td style="min-width: 25%;<?php echo "$style";?>"><?php echo $rowz['keterangan'];?></td>
            <td align="right" style="<?php echo "$style";?>">
               <?php 
                  echo ($rowz['debet']!=0)?rupiah($rowz['debet']):"-";
               ?>
            </td>
            <td align="right" style="<?php echo "$style";?>">
               <?php 
                  echo ($rowz['kredit']!=0)?rupiah($rowz['kredit']):"-";
               ?>
            </td>
            <td align="right" style="<?php echo "$style";?>"><?php echo rupiah($rowz['saldo']);?></td>
            <td style="width:10%;<?php echo "$style";?>" class="aksi">
               <?php 
                 if($rowz['status'] == 1){
                     if($rowz['debet'] == 0){
                         echo anchor('keuangan_donatur_tunggal/unapprove_keuangan_donatur_tunggal/kredit/'.$rowz['id'].'/'.$bulan.'/'.$thn.'/'.$rowz['kredit'], 'Unapprove', 'class=delete title=Unapprove');
                     }else if($rowz['kredit'] == 0){
                         echo anchor('keuangan_donatur_tunggal/unapprove_keuangan_donatur_tunggal/debet/'.$rowz['id'].'/'.$bulan.'/'.$thn.'/'.$rowz['debet'], 'Unapprove', 'class=delete title=Unapprove');
                     }
                     
                 }else{
               ?>
                <input type="checkbox" value="<?php echo $rowz['id'];?>" name="id_keuangan_donatur_tunggal[]" class="check" onClick="checkList(this)"/>
               <?php 
                   if($rowz['debet'] == 0){
                     echo "<input type='hidden' name='pengeluaran[]' value='".$rowz['kredit']."' class='jumlah'/>";  
                   }else if($rowz['kredit'] == 0){
                     echo "<input type='hidden' name='pemasukan[]' value='".$rowz['debet']."' class='jumlah'/>";    
                   }
                 }
               ?>
            </td>
        </tr>
        <?
              }
          }
        ?>
    </table>
</div>
</fieldset>    
<fieldset style="border: 1px dotted #999999">
    <legend>Transaksi Collecting Day</legend>
    <div class="data-list">
    <table class="tabel" style="width:100%">
        <tr>
            <th>Kegiatan</th>
            <th>Tanggal</th>
            <th>Petugas</th>
            <th>Lokasi</th>
            <th>Jumlah(Rp.)</th>
            <th>Aksi</th>
        </tr>    
            <?php
                $total = 0;
                foreach ($listCollectingDay as $rows){
                ($rows['status'] == 0)?$style = "background:#fed6db": $style = "background:#d6fedb"; 
                if($rows['status'] == 0) $disable = "";
            ?>
        <tr style="<?php echo "$style";?>">
            <td><?php echo $rows['kegiatan'];?></td>
            <td style="width:14%"><?php echo datefmysql($rows['tanggal']);?></td>
            <td><?php echo $rows['petugas'];?></td>
            <td><?php echo $rows['lokasi'];?></td>
            <td align="right"><?php echo rupiah($rows['total']);?></td>
            <td class="aksi" style="width:10%">
              <?php 
                if($rows['status'] == 1){
                    echo anchor('collecting_day/unapprove_collecting_day/'.$rows['id'].'/'.$bulan.'/'.$thn.'/'.$rows['total'], 'Unapprove', 'class=delete title=unapprove');
                }else{
             ?>
                <input type="checkbox" value="<?php echo $rows['id'];?>" name="id_collecting_day[]" class="check" onClick="checkList(this)"/>
                <input type="hidden" name="pemasukan[]" value="<?php echo $rows['total'];?>" class="jumlah"/>
             <?php   
                }
              ?>
            </td>
        </tr>
            <?php
                $total = $total + $rows['total'];
                }
            ?>
    </table>
    </div>    
</fieldset>
<fieldset style="border: 1px dotted #999999">
    <legend>Pemberian Beasiswa</legend>
    <div class="data-list">
        <table class="tabel" style="width:100%">
            <tr>
                <th>Tanggal</th>
                <th>Petugas</th>
                <th>Adik Asuh</th>
                <th>Sekolah</th>
                <th>Kelas</th>
                <th>Keterangan</th>
                <th>Jumlah (Rp.)</th>
                <th>Aksi</th>
            </tr>
            <?php
              $totals = 0;
              foreach ($listPemberianBeasiswa as $data){
              ($data['status'] == 0)?$style = "background:#fed6db": $style = "background:#d6fedb"; 
              if($data['status'] == 0) $disable = "";    
            ?>
            <tr style="<?php echo "$style";?>">
                <td><?php echo datefmysql($data['tanggal'])?></td>
                <td><?php echo $data['petugas'];?></td>
                <td><?php echo $data['adik_asuh'];?></td>
                <td><?php echo $data['sekolah'];?></td>
                <td><?php echo $data['kelas'].' '.$data['tingkat_pendidikan'];?></td>
                <td><?php echo $data['keterangan'];?></td>
                <td align="right"><?php echo rupiah($data['jumlah']);?></td>
                <td class="aksi" style="width:10%">
                  <?php 
                    if($data['status'] == 1){
                        echo anchor('pemberian_beasiswa/unapprove_pemberian_beasiswa/'.$data['id_pemberian'].'/'.$bulan.'/'.$thn.'/'.$data['jumlah'], 'Unapprove', 'class=delete title=Unapprove');
                    }else{
                  ?>
                    <input type="checkbox" value="<?php echo $data['id_pemberian'];?>" name="id_pemberian_beasiswa[]" class="check" onClick="checkList(this)"/>
                    <input type="hidden" name="pengeluaran[]" value="<?php echo $data['jumlah'];?>" class="jumlah"/>
                  <?php  
                    }
                  ?>
                </td>
            </tr>
            <?
             $totals = $totals + $data['jumlah'];
              }
            ?>
        </table>
    </div>    
</fieldset>
<fieldset style="border: 1px dotted #999999">
    <legend>Transaksi Pemasukan</legend>
    <div class="data-list">
        <table class="tabel" style="width:100%">
            <tr>
                <th>Tanggal</th>
                <th>Petugas</th>
                <th>Keterangan</th>
                <th>Jumlah (Rp.)</th>
                <th>Aksi</th>
            </tr>
            <?php
                $totDebet = 0;
                foreach ($listPemasukan as $debet){
                ($debet['status'] == 0)?$style = "background:#fed6db": $style = "background:#d6fedb"; 
                if($debet['status'] == 0) $disable = "";        
            ?>
            <tr style="<?php echo "$style";?>">
                <td style="width:17%"><?php echo datefmysql($debet['tanggal']);?></td>
                <td><?php echo $debet['nama'];?></td>
                <td><?php echo $debet['keterangan'];?></td>
                <td style="text-align:right;width:15%"><?php echo rupiah($debet['jumlah']);?></td>
                <td class="aksi" style="width:10%">
                   <?php 
                     if($debet['status'] == 1){
                         echo anchor('pemasukan/unapprove_pemasukan/'.$debet['id'].'/'.$bulan.'/'.$thn.'/'.$debet['jumlah'], 'Unapprove', 'class=delete title=Unapprove');      
                     }else{
                   ?>
                    <input type="checkbox" value="<?php echo $debet['id'];?>" name="id_pemasukan[]" class="check" onClick="checkList(this)"/>
                    <input type="hidden" name="pemasukan[]" value="<?php echo $debet['jumlah'];?>" class="jumlah"/>
                   <? 
                     }
                   ?>
                </td>
            </tr>
            <?php
              $totDebet = $totDebet + $debet['jumlah'];
                }
            ?>
        </table>
    </div>
</fieldset>
<fieldset style="border: 1px dotted #999999">
    <legend>Transaksi Pengeluaran</legend>
    <div class="data-list">
        <table class="tabel" style="width:100%">
            <tr>
                <th>Tanggal</th>
                <th>Petugas</th>
                <th>Keterangan</th>
                <th>Jumlah (Rp.)</th>
                <th>Aksi</th>
            </tr>
            <?php
                $totKredit = 0;
                foreach ($listPengeluaran as $kredit){
                ($kredit['status'] == 0)?$style = "background:#fed6db": $style = "background:#d6fedb"; 
                if($kredit['status'] == 0) $disable = "";        
            ?>
            <tr style="<?php echo "$style";?>">
                <td style="width:17%"><?php echo datefmysql($kredit['tanggal']);?></td>
                <td><?php echo $kredit['nama'];?></td>
                <td><?php echo $kredit['keterangan'];?></td>
                <td style="text-align:right;width:15%"><?php echo rupiah($kredit['jumlah']);?></td>
                <td class="aksi" style="width:10%">
                    <?php 
                     if($kredit['status'] == 1){
                         echo anchor('pengeluaran/unapprove_pengeluaran/'.$kredit['id'].'/'.$bulan.'/'.$thn.'/'.$kredit['jumlah'], 'Unapprove', 'class=delete title=Unapprove');      
                     }else{
                    ?>
                    <input type="checkbox" value="<?php echo $kredit['id'];?>" name="id_pengeluaran[]" class="check" onClick="checkList(this)"/>
                    <input type="hidden" name="pengeluaran[]" value="<?php echo $kredit['jumlah'];?>" class="jumlah"/>
                    <?
                     }
                   ?>
                </td>
            </tr>
            <?php
              $totKredit = $totKredit + $kredit['jumlah'];
                }
            ?>
        </table>
    </div>
</fieldset>
<?php
  echo form_hidden('bulan', $bulan);
  echo form_hidden('tahun', $thn);
  $totalAll = ($saldo+$total+$totDebet)-($totals+$totKredit);
  echo form_hidden('total',$totalAll);
  
  if($disable == ''){
?>
<div style="float: right;margin-top: 10px;">
        <?php
          echo form_button("approve","Check All", "class='button' id='checkAll'");
          echo '<input type=hidden value=1 class=checkAll>';
        ?>
</div>
<?php
  }
?>
<div class="data-input" style="clear: left;">
        <?php
          echo form_submit("approve","Approve", "class='button' $disable");
        ?>
</div>
<?php
  echo form_close();
?>